﻿using EkStudio.com.bean.xml.reflection;
using EkStudio.com.bean.xml.RootInterface;
using System.Collections.Generic;
using System;

namespace EkStudio.com.bean.xml.BillMapping
{
    public class BillDataMapGroupRoot: BillUiFormatContainer
    {
        private int maxid = 0;

        private List<BillDataMapGroupItem> fieldsProperties = null;

        public BillDataMapGroupRoot()
        {
            fieldsProperties = new List<BillDataMapGroupItem>();
        }


        [Xml]
        public int Maxid
        {
            get { return maxid; }
            set { maxid = value; }
        }

       

        [XmlElement]
        public List<BillDataMapGroupItem> FieldsProperties
        {
            get { return fieldsProperties; }
            set { fieldsProperties = value; }
        }
        [XmlTransient]
        public object ParentBean
        {
            get
            {
                return null;
            }

            set
            {
                
            }
        }
        public object Clone()
        {
            throw new NotImplementedException();
        }


        public void addNode(BillUiFormatNode node, BillFormatModule format)
        {
            BillDataMapGroupItem item = node as BillDataMapGroupItem;
            item.LanguageTexts = getNLanguageText(format);
            fieldsProperties.Add(node as BillDataMapGroupItem);
        }

        public string getNLanguageText(BillFormatModule format)
        {
            String result = "";
            int tempMaxid = maxid + 1;
            if (format != null)
            {
                string text = format.getLanguageText();
                int index = text.IndexOf("Caption");
                int length = text.Length - 7;
                result = text.Substring(0, length);
                result = result + "Groups[" + tempMaxid + "].Caption";
            }
            this.Maxid = tempMaxid;
            return result;
        }

        public void moveDown(BillUiFormatNode node)
        {
        }

        public void moveUp(BillUiFormatNode node)
        {
        }

        public void removeNode(BillUiFormatNode node)
        {

        }

        public void updateLanguageText(BillFormatModule format)
        {
            maxid = 0;
            if(fieldsProperties!=null&& fieldsProperties.Count > 0)
            {
                foreach(BillDataMapGroupItem it in fieldsProperties)
                {
                    it.LanguageTexts = getNLanguageText(format);
                }
            }
        }
    }
}
